package com.easygoods.dao;


import com.easygoods.base.BaseDao;
import com.easygoods.entity.OrderGoods;
import com.easygoods.entity.OrderInfo;
import com.easygoods.enums.OrderState;
import com.easygoods.response.OrderDetailResponse;
import com.easygoods.response.OrderDetailResponseItem;
import com.easygoods.response.OrderListResponse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhq
 * @date 2019/1/2 14:30
 */
@Repository
public interface OrderInfoDao extends BaseDao<OrderInfo> {
    //查询在途的订单主键
    List<String> getUnderWayIdList(@Param("state") OrderState state, RowBounds rowBounds);

    //查询在途的订单主键
    default List<String> getUnderWayIdList(RowBounds rowBounds) {
        return this.getUnderWayIdList(OrderState.UnderWay, rowBounds);
    }

    //根据memberId和state查询订单列表
    List<OrderListResponse> getOrderList(@Param("memberId") String memberId, @Param("stateList") List<OrderState> stateList, RowBounds rowBounds);

    //获取订单详情
    OrderDetailResponse getOrderDetail(@Param("orderId") String orderId);

    //获取订单对应的商品列表
    List<OrderDetailResponseItem> getOrderGoodsList(@Param("orderId") String orderId);

    //查询该用户下是否已经有了订单
    boolean isOrderInfoExist(@Param("memberId") String memberId);

    //查询已完成、未结算、超过退款时间的订单
    List<String> getToSettleOrderIdList(@Param("state") OrderState state);

    //查询已完成、未结算、超过退款时间的订单
    default List<String> getToSettleOrderIdList() {
        return this.getToSettleOrderIdList(OrderState.Completed);
    }

    //查询该用户邀请的多个用户的多个订单下多个商品
    List<OrderGoods> getInvitedUnsettledOrderGoods(@Param("memberId") String memberId, @Param("stateList") OrderState[] stateList);

    //查询该用户邀请的多个用户的多个订单下多个商品
    default List<OrderGoods> getInvitedUnsettledOrderGoods(String memberId) {
        final OrderState[] orderStates = {OrderState.ToSend, OrderState.UnderWay, OrderState.Completed};
        return this.getInvitedUnsettledOrderGoods(memberId, orderStates);
    }

    //查询超时未支付的订单的id
    List<String> getExpiredOrderIdList(@Param("state") OrderState state, @Param("expiredMinutes") int expiredMinutes);

    //查询超时未支付的订单的id
    default List<String> getExpiredOrderIdList(int expiredMinutes) {
        return this.getExpiredOrderIdList(OrderState.ToPay, expiredMinutes);
    }

    boolean isFirstBuy(@Param("memberId") String memberId, @Param("completedStateList") OrderState[] completedStateList);

    //是否首次购买
    default boolean isFirstBuy(String memberId) {
        return this.isFirstBuy(memberId, new OrderState[]{OrderState.Completed, OrderState.Settled});
    }
}
